home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / BYACC__ / TEXT.C < prev    next >
C/C++ Source or Header  |  1989-11-19  |  694b  |  44 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "files.h"
  4. #include "new.h"
  5. #include "text.h"
  6.  
  7.  
  8. text *
  9. mk_text(lineno, s, n)
  10. int lineno;
  11. register char *s;
  12. register int n;
  13. {
  14.   register int i;
  15.   register char *t;
  16.   register text *p;
  17.  
  18.   p = (text *) allocate((unsigned) (sizeof(text) + n*sizeof(char)));
  19.   p->start_line = lineno;
  20.   p->length = n;
  21.   t = p->ch;
  22.   for (i = n; i > 0; i--)
  23.     *t++ = *s++;
  24.   return (p);
  25. }
  26.  
  27. free_text(tp)
  28. text *tp;
  29. {
  30.   FREE(tp);
  31. }
  32.  
  33. write_text(tp, fp)
  34. register text *tp;
  35. register FILE *fp;
  36. {
  37.   register int i;
  38.   register char *s;
  39.  
  40.   fprintf(fp, "\n#line %d \"%s\"\n", tp->start_line, input_file_name);
  41.   s = tp->ch;
  42.   for (i = tp->length; i > 0; s++, i--) putc(*s, fp);
  43. }
  44.